﻿using UnityEngine;
using TinyWnd;

public class WndLevelDetaiContent : WndContentData
{
    public int id;
    public string desc;
}

public class LevelDetailWnd : Wnd
{
    UILabel label;
    TweenAlpha twAlpha;
    GameObject goBtn;

    protected override void OnAwake()
    {
        _wndId = WndId.levelDetail;
        _unifiedClose = true;
        _colliderMode = WndColliderMode.transparent;

        var tran = transform;
        label = Utility.FindChild<UILabel>(tran, "Bg/Content");
        twAlpha = Utility.FindChild<TweenAlpha>(tran, "Bg");
        goBtn = Utility.FindChild(tran, "Bg/BtnStart").gameObject;

        UIEventListener.Get(goBtn).onClick = delegate
        {
            BattleMgr.inst.EnterBattle();
        };
    }

    protected override void OnShow(WndContentData content)
    {
        var data = content as WndLevelDetaiContent;
        label.text = string.Format("level:{0} {1}", data.id, data.desc);

        gameObject.SetActive(true);
        twAlpha.onFinished.Clear();
        twAlpha.PlayForward();
    }

    protected override void OnHide()
    {
        twAlpha.SetOnFinished(CbFinishClose);
        twAlpha.PlayReverse();
    }

    void CbFinishClose()
    {
        gameObject.SetActive(false);
    }
}
